package com.jgraves.WikiToSpeech.objects;

import java.util.ArrayList;

/** Object holding set of dictionary entries
 * @author johngraves
 */
public class Dictionary {

	private ArrayList<DictionaryEntry> dictionary = new ArrayList<DictionaryEntry>();

	public ArrayList<DictionaryEntry> getDictionary() {
		return dictionary;
	}

	public void setDictionary(ArrayList<DictionaryEntry> dictionary) {
		this.dictionary = dictionary;
	}
	
	public ArrayList<DictionaryEntry> missingValues() {
		ArrayList<DictionaryEntry> missingValues  = new ArrayList<DictionaryEntry>();
		for (DictionaryEntry de: dictionary) {
			if (""==de.getValue()){
				missingValues.add(de);
			}
		}
		return missingValues;
	}
	
	public ArrayList<DictionaryEntry> missingQuestions() {
		ArrayList<DictionaryEntry> missingQuestions  = new ArrayList<DictionaryEntry>();
		for (DictionaryEntry de: dictionary) {
			if (""==de.getQuestionToFill()){
				missingQuestions.add(de);
			}
		}
		return missingQuestions;
	}

	public boolean contains(String token) {
		Boolean found = false;
		for (DictionaryEntry de: dictionary) {
			if (de.getToken().equals(token)) {
				found = true;
				break;
			}
		}
		return found;
	}
	
	public String getValueForToken(String token) {
		String found = "";
		for (DictionaryEntry de: dictionary) {
			if (de.getToken().equals(token)) {
				found = de.getValue();
				break;
			}
		}
		return found;
	}

	public String getQuestionForToken(String token) {
		String found = "";
		for (DictionaryEntry de: dictionary) {
			if (de.getToken().equals(token)) {
				found = de.getQuestionToFill();
				break;
			}
		}
		return found;
	}
	
	public DictionaryEntry getEntryForToken(String token) {
		DictionaryEntry found = null;
		for (DictionaryEntry de: dictionary) {
			if (de.getToken().equals(token)) {
				found = de;
				break;
			}
		}
		return found;
	}
	
	public void addEntry(DictionaryEntry de) {
		dictionary.add(de);
	}
	
	public void updateEntry(DictionaryEntry de) {
		for (DictionaryEntry deInDictionary: dictionary) {
			if (de.getToken().equals(deInDictionary.getToken())) {
				dictionary.remove(dictionary.indexOf(deInDictionary));
				dictionary.add(de);
				break;
			}
		}
	}
	
}
